package leetcode.year2021.month10;

public class _07_01LongestPalindrome5 {
  public String longestPalindrome(String s) {
    if (s.length() == 0 || s == null) {
      return "";
    }
    int[] range = new int[2];
    char[] str = s.toCharArray();
    for (int i = 0; i < str.length - 1; i++) {
      i = findMaxLength(str, i, range);
    }
    return s.substring(range[0], range[1] + 1);
  }

  private int findMaxLength(char[] str, int low, int[] range) {
    int high = low;
    while (high < str.length - 1 && str[low] == str[high + 1]) {
      high++;
    };

    int env=high;

    while (low > 0 && high < str.length-1 && str[low - 1] == str[high + 1]) {
      high++;
      low--;
    }

    if (range[1]-range[0] < high-low){
      range[0]=low;
      range[1]=high;
    }

    return env;
  }
  /**
   * 给你一个字符串 s，找到 s 中最长的回文子串。
   *
   *  
   * 示例 1：
   *
   * 输入：s = "babad"
   * 输出："bab"
   * 解释："aba" 同样是符合题意的答案。
   * 示例 2：
   *
   * 输入：s = "cbbd"
   * 输出："bb"
   * 示例 3：
   *
   * 输入：s = "a"
   * 输出："a"
   * 示例 4：
   *
   * 输入：s = "ac"
   * 输出："a"
   *
   */
}
